package com.itboye.jinpuyiyuan.activity.home.register;

import android.app.AlertDialog;
import android.os.Build;
import android.os.Bundle;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.adapter.DateRecylerAdapter;
import com.itboye.jinpuyiyuan.adapter.RegisterDoctorDetailAdapter;
import com.itboye.jinpuyiyuan.base.BaseActivity;
import com.itboye.jinpuyiyuan.bean.DateBean;
import com.itboye.jinpuyiyuan.bean.RegisterDoctorDetail;
import com.itboye.jinpuyiyuan.utils.dialog.RxDialogDate;

import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by Administrator on 2017/12/9 0009.
 */

public class RegisterDetailActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    //title
    private ImageView leftImg,rightImg;
    private TextView leftTv,tvTitle;
    private RelativeLayout rlLeft,toobar;

    private ListView registerDoctorList;
    private RegisterDoctorDetailAdapter registerDoctorDetailAdapter;
    private ArrayList<RegisterDoctorDetail> list;
    private RecyclerView recyclerView;
    private DateRecylerAdapter dateRecylerAdapter;
    private ArrayList<DateBean> dateList;//时间bean list
    private RxDialogDate dialogDate;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_registerdetail);
        leftTv.setVisibility(View.GONE);
        rightImg.setVisibility(View.GONE);
        tvTitle.setText(getIntent().getStringExtra("title"));
        dialogDate=new RxDialogDate(this,0,24,"选择挂号时间","确定挂号");
        dialogDate.show();
        initData();

    }

    private void initData() {
        list=new ArrayList<>();
        dateList=new ArrayList<>();

        for (int i=0;i<6;i++){
            RegisterDoctorDetail registerDoctorDetail = new RegisterDoctorDetail();
            list.add(registerDoctorDetail);
        }

//        registerDoctorDetailAdapter=new RegisterDoctorDetailAdapter(this,list);
//        registerDoctorList.setAdapter(registerDoctorDetailAdapter);
        getDateList();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        dateRecylerAdapter=new DateRecylerAdapter(this,dateList);
        recyclerView.setAdapter(dateRecylerAdapter);
        registerDoctorList.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //item提交按钮点击事件
        view.findViewById(R.id.tvRegister).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){

            case R.id.rlLeft:
            case R.id.leftImg:
                this.finish();
                break;
        }
    }

    public void getDateList(){
        Calendar instance = Calendar.getInstance();
        instance.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));

        String month = String.valueOf(instance.get(Calendar.MONTH)+1);
        String day = String.valueOf(instance.get(Calendar.DAY_OF_MONTH));
        String mWay = String.valueOf(instance.get(Calendar.DAY_OF_WEEK));
        mWay= getWeekday(mWay);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd");
        instance.set(Calendar.DAY_OF_MONTH,1);
        Log.d("simpleDate==",simpleDateFormat.format(instance.getTime())+"");
        int format1 = Integer.valueOf(simpleDateFormat.format(instance.getTime()));
        instance.set(Calendar.DAY_OF_MONTH,instance.getActualMaximum(Calendar.DAY_OF_MONTH));
        Log.d("simpleDate==",simpleDateFormat.format(instance.getTime())+"");
        int format2 = Integer.valueOf(simpleDateFormat.format(instance.getTime()));
        for (int i=format1;i<format2;i++){
            instance.set(Calendar.DAY_OF_MONTH,i);
            DateBean dateBean = new DateBean();
            dateBean.setDay(i+"");
            dateBean.setMonth(month);
            dateBean.setWeek("星期"+getWeekday(String.valueOf(instance.get(Calendar.DAY_OF_WEEK))));
            dateList.add(dateBean);
        }

    }

    public String getWeekday(String mWay){

        if("1".equals(mWay)){
            return mWay ="日";
        }else if("2".equals(mWay)){
            return mWay ="一";
        }else if("3".equals(mWay)){
            return mWay ="二";
        }else if("4".equals(mWay)){
            return mWay ="三";
        }else if("5".equals(mWay)){
            return mWay ="四";
        }else if("6".equals(mWay)){
            return mWay ="五";
        }else if("7".equals(mWay)){
            return mWay ="六";
        }
        return "";
    }
}
